#include "tablesummator.h"
#include "../../app/TestTraining/summater.h"
#include <QObject>
#include <QDialog>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QDebug>

TableSummator::TableSummator(QWidget *parent):QDialog(parent), m_sum(new Summater(this))

{
       m_label=new QLabel("Sum = ", this);
       QHBoxLayout *h1lay=new QHBoxLayout();
       QHBoxLayout *h2lay=new QHBoxLayout();
       QPushButton *m_setButton = new QPushButton("set", this);

       h1lay->addWidget(new QLabel("A:", this));
       lineA = new QLineEdit("", this);
       h1lay->addWidget(lineA);

       h2lay->addWidget(new QLabel("B:", this));
       lineB = new QLineEdit("", this);
       h2lay->addWidget(lineB);

       setLayout(new QVBoxLayout);

       layout()->addWidget(m_label);
       layout()->addItem(h1lay);
       layout()->addItem(h2lay);
       layout()->addWidget(m_setButton);

       connect(m_setButton, SIGNAL(clicked()), this, SLOT(setSum()));
}

void TableSummator::setSum()
{    
    m_sum->setA(lineA->text().toInt());    
    m_sum->setB(lineB->text().toInt());
    int sum = m_sum->sum();    
    m_label->setText(QString("Sum : ") + QString::number(sum));
}
